from sqlalchemy import create_engine, ForeignKey, Column, String, Integer, CHAR
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import time

Base = declarative_base()

class MessageBoard(Base):
    __tablename__ = "message_board"

    mid = Column("ID", Integer, primary_key=True)
    content = Column("content", String)
    person = Column("person", String)
    state = Column("state", String)
    time = Column("time", String)

    def __init__(self, mid,content,person,state,time):
        self.mid = mid
        self.content = content
        self.person = person
        self.state = state
        self.time = time

    def __repr__(self):
        return f"({self.mid}) {self.content} {self.person} {self.state} {self.time}"


if __name__ == '__main__':
    t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    engine = create_engine("mysql://scott:tiger@root/homework", echo=True)
    Base.metadata.create_all(bind=engine)

    Session = sessionmaker(bind=engine)
    session = Session()

    message_board = MessageBoard(5, "test", "cyz", "reviewint", t)
    session.add(message_board)
    session.commit()